package com.zbs.simbot.constants;

import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MhyConstant {

    public MhyConstant() {
    }

    // 米游社正在扫码登录的用户
    public static final Map<String,Boolean> qrLoginRunning = new HashMap<>();
    // 米游社手机端登录类型
    public static final Integer APP_ID = 4;
    // 获取二维码
    public static final String MHY_GET_QR_CODE_URL = "https://hk4e-sdk.mihoyo.com/hk4e_cn/combo/panda/qrcode/fetch";
    // 查询二维码状态
    public static final String MHY_QUERY_QR_CODE_URL = "https://hk4e-sdk.mihoyo.com/hk4e_cn/combo/panda/qrcode/query";
    // 登录获取token
    public static final String GET_TOKEN_BY_GAME_TOKEN_URL = "https://passport-api.mihoyo.com/account/ma-cn-session/app/getTokenByGameToken";
    // 登录获取 cookie
    public static final String GET_COOKIE_ACCOUNT_INFO_BY_GAME_TOKEN_URL = "https://api-takumi.mihoyo.com/auth/api/getCookieAccountInfoByGameToken";
    // 获取米哈游用户基础信息
    public static final String GET_USER_FULL_INFO_URL = "https://bbs-api.mihoyo.com/user/wapi/getUserFullInfo?gids=2";
    // 获取游戏角色 mys 国服  hoyolab 国际服 （ps：不是原神角色，应该是叫游戏身份，米哈游旗下有很多角色，那么这个可以获取你玩过的原神，崩坏等游戏角色）
    public static final Map<String,String> USER_GAME_ROLES_URL = new HashMap<>();
    // 随机种子
    public static final String SEED = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    // 服务类型 mys 国服  hoyolab 国际服
    public static final String[] SERVS = new String[]{"mys", "hoyolab"};
    // UID 匹配正则
    private static final Pattern uidReg = Pattern.compile("[1|2|5-9][0-9]{8}");
    // 登录错误日志
    public static final String ERROR_TIPS = "登录失败，请检查日志";

    static {
        // 米哈游游戏角色列表 mys 国服  hoyolab 国际服
        USER_GAME_ROLES_URL.put("mys","https://api-takumi.mihoyo.com/binding/api/getUserGameRolesByCookie?game_biz=hk4e_cn");
        USER_GAME_ROLES_URL.put("hoyolab","https://api-os-takumi.mihoyo.com/binding/api/getUserGameRolesByCookie?game_biz=hk4e_global");
    }

    public static String getUidToMsg(String msg) {
        if (StringUtils.hasLength(msg)) {
            Matcher matcher = uidReg.matcher(msg);
            if (matcher.find()) {
                return matcher.group();
            }
        }
        return "";
    }

    public static String getServer(String uid) {
        char c = uid.charAt(0);
        return switch (c) {
            case '1', '2' -> "cn_gf01"; // 官服
            case '5' -> "cn_qd01"; // B服
            case '6' -> "os_usa"; // 美服
            case '7' -> "os_euro"; // 欧服
            case '8' -> "os_asia"; // 亚服
            case '9' -> "os_cht"; // 港澳台服
            default -> "cn_gf01"; // 官服
        };
    }
}
